package com.xiebiao.module;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;
import java.util.function.Predicate;

/**
 * 实现 {@link ImportSelector} 接口，可以更灵活地控制Bean的初始化.
 *
 * @Description: XXX
 * @Author: Bill Xie
 * @Create: 2025/6/19 10:06
 **/
public class MyModuleImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        Map<String, Object> maps = importingClassMetadata.getAnnotationAttributes(EnableMyModule.class.getName());
        if (null != maps.get("enabled") && (Boolean) maps.get("enabled")) {
            return new String[]{MyModuleConfiguration.class.getName()};
        }
        return new String[0];
    }

    @Override
    public Predicate<String> getExclusionFilter() {
        return ImportSelector.super.getExclusionFilter();
    }
}
